#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

bool Simple(int a) {
    for (int i = 2; i <= a / 2; i++) {
        if (a % i == 0) {
            return false;
        }
    }
    return true;
}

int NextS(int a) {
    while (!Simple(a)) {
        a++;
    }
    return a;
}

int BeforeS(int a) {
    while (!Simple(a)) {
        a--;
    }
    return a;
}

int main() {
    string input;
    getline(cin, input);
    vector<string> a;
    string temp = "";
    for (char c : input) {
        if (c == ' ') {
            a.push_back(temp);
            temp = "";
        } else {
            temp += c;
        }
    }
    a.push_back(temp);

    int s = a.size();
    if (s <= 2) {
        cout << "Wrong input" << endl;
    } else {
        vector<char> c;
        for (string i : a) {
            if (i == "one") {
                c.push_back('1');
            } else if (i == "two") {
                c.push_back('2');
            } else if (i == "three") {
                c.push_back('3');
            } else if (i == "four") {
                c.push_back('4');
            } else if (i == "five") {
                c.push_back('5');
            } else if (i == "six") {
                c.push_back('6');
            } else if (i == "seven") {
                c.push_back('7');
            } else if (i == "eight") {
                c.push_back('8');
            } else if (i == "nine") {
                c.push_back('9');
            } else if (i == "zero") {
                c.push_back('0');
            }
        }
        string e(c.begin(), c.end());
        int r = stoi(e);
        int d = BeforeS(r);
        int x = NextS(r);
        if (abs(d - r) < abs(x - r)) {
            cout << d << endl;
        } else {
            cout << x << endl;
        }
    }
    return 0;
}